package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.AccountApply;
import com.briup.jz.bean.extend.AccountApplyExtend;
import com.briup.jz.service.AccountApplyService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import com.briup.jz.utils.PageVM;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="accountapply(账户变动)相关接口")
@Validated
@RestController
@RequestMapping("/accountapply")
public class AccountApplyController{
	@Autowired
	private AccountApplyService accountapplyService;
	
/*	@ApiOperation(value = "查询所有账户分类")*/
	@ApiOperation("多条件符合查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value="编号",paramType="query"),
		@ApiImplicitParam(name="status",value="状态[未审核、通过、不通过]",paramType="query"),
		@ApiImplicitParam(name="applyType",value="操作类型",paramType="query"),
		@ApiImplicitParam(name="userId",value="用户id",paramType="query"),
	})
	@GetMapping("query")
    public Message query(Long id,String status,String applyType,Long userId){
        List<AccountApply> list = accountapplyService.query(id, status, applyType, userId);
        return MessageUtil.success(list);
    }
	
	@ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query"),
    })
    public Message deleteById(@NotNull Long id){
    	accountapplyService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新地址分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "query"),
            @ApiImplicitParam(name="money",value = "存款",paramType = "query"),
            @ApiImplicitParam(name="applyType",value = "申请类型",paramType = "query"),
            @ApiImplicitParam(name="applyTime",value = "申请时间",paramType = "query"),
            @ApiImplicitParam(name="status",value = "审核",paramType = "query"),
            @ApiImplicitParam(name="userId",value = "用户id",paramType = "query"),
            @ApiImplicitParam(name="reason",value = "描述信息",paramType = "query"),
//            @ApiImplicitParam(name="userId",value = "用户编号",paramType = "query"),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(AccountApply accountapply){
    	accountapplyService.saveOrUpdate(accountapply);
        return MessageUtil.success("更新成功");
    }
    
    @GetMapping("checkNoPass")
    @ApiOperation(value = "审核不通过")
    public Message checkNoPass(Long id,String reason) {
    	accountapplyService.checkNoPass(id, reason);
		return MessageUtil.success("成功");
	}
    
    @GetMapping("checkPass")
    @ApiOperation(value = "审核通过")
    public Message checkPass(Long id) {
    	accountapplyService.checkPass(id);
		return MessageUtil.success("成功");
	}
    
    @GetMapping("pageQueryAccountApply")
    @ApiOperation("分页查询账户变动申请")
    public Message pageQueryAccountApply(PageVM<AccountApply> page) {
		return MessageUtil.success("");
	}
    
    @GetMapping("revokeAccountApply")
    @ApiOperation("撤销账户变动申请")
    @ApiImplicitParam(name="id", value="id", paramType = "query",dataType="long")
    public Message revokeAccountApply(Long id) {
    	accountapplyService.revokeAccountApply(id);
		return MessageUtil.success("成功");
	}
    
    @PostMapping("submitAccountApply")
    @ApiOperation("提交账户变动申请")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id", paramType = "query",dataType="long"),
        @ApiImplicitParam(name="applyTime",paramType = "query",dataType="long"),
        @ApiImplicitParam(name="status",paramType = "query"),
        @ApiImplicitParam(name="reason",paramType = "query"),
        @ApiImplicitParam(name="money",value = "变动金额",paramType = "query",required=true),
        @ApiImplicitParam(name="applyType",value = "账户变动类型【提现】",paramType = "query",required=true),
        @ApiImplicitParam(name="userId",value = "用户编号",paramType = "query",required=true),
        })
    public Message submitAccountApply(AccountApply accountapply) {
    	accountapplyService.saveOrUpdate(accountapply);
		return MessageUtil.success("");
	}
    
    @ApiOperation(value="多条件符合级联查询",notes="级联查询出账户记录所属的用户")
	@ApiImplicitParams({
		@ApiImplicitParam(name="status",value="状态[未审核、通过、不通过]",paramType="query"),
		@ApiImplicitParam(name="applyType",value="申请类型[提现、充值]",paramType="query"),
		@ApiImplicitParam(name="userId",value="所属用户id",paramType="query",dataType="Long"),
	})
	@GetMapping("queryCascade")
    public Message queryCascade(String status,String applyType,Long userId){
		List<AccountApplyExtend> list = accountapplyService.queryCascade(status, applyType, userId);
        return MessageUtil.success(list);
    }
}

